﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.RefundCommand;
using D.Medicalcare.Read.API.Dtos;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.RefundHarder
{
    public class GetAccountbalanceHarder : IRequestHandler<GetAccountbalanceCommand, APIResult<Accountbalance>>
    {

        private readonly IBaseRepository<Accountbalance> accountbalanceRepository;

        public GetAccountbalanceHarder(IBaseRepository<Accountbalance> accountbalanceRepository)
        {
            this.accountbalanceRepository = accountbalanceRepository;
        }

        public async Task<APIResult<Accountbalance>> Handle(GetAccountbalanceCommand request, CancellationToken cancellationToken)
        {
            APIResult<Accountbalance> result = new APIResult<Accountbalance>
            {
                Code = APIEnum.Mvc,
                Msg = "查询成功"
            };

            var list = accountbalanceRepository.GetAll().Where(x => x.PatientId == request.PatientId);
            result.Data = list.First();

            return await Task.FromResult(result);
        }
    }
}
